from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage, SKU
from meiduo_admin import my_serializers
from meiduo_admin.views.users import UserPageNum


class ImageView(ModelViewSet):
    """
    商品图片管理
    增删改查功能则使用ModelViewSet
    """
    # 指定查询集
    queryset = SKUImage.objects.all()

    # 指定序列化器
    serializer_class = my_serializers.ImageSerializer

    # 指定分页器
    pagination_class = UserPageNum


    # 获取spu的简要信息
    def simple(self, request):
        datas = SKU.objects.all()
        ser = my_serializers.SKUSimple(datas, many=True)
        return Response(ser.data)

